package com.heima.comment.controller;

import com.heima.comment.service.CommentService;
import com.heima.model.common.dtos.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/api/v1/comment")
@Slf4j
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * app端文章发布评论
     *
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody CommentSaveDto commentSaveDto) {
        log.info("app端文章发布评论: {}", commentSaveDto);

        return commentService.save(commentSaveDto);

    }

    /**
     * app评论点赞
     *
     * @return
     */
    @PostMapping("/like")
    public ResponseResult commentLike(@RequestBody CommentLikeDto commentLikeDto) {
        log.info("app评论点赞: {}",commentLikeDto);
        return commentService.commentLike(commentLikeDto);
    }

    /**
     * app端文章评论列表
     * @param commentDto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult loadCommentList(@RequestBody CommentDto commentDto) {
        log.info("app端文章评论列表: {}", commentDto);

        return commentService.loadCommentList(commentDto);
    }

}
